package at.ac.lbg.media.vis.framework.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import at.ac.lbg.media.vis.framework.model.Artwork;
import at.ac.lbg.media.vis.framework.model.ThemeLandscapeHexboardDataItem;

import no.uib.cipr.matrix.NotConvergedException;

import incboard.api.DataModelInterface;
import incboard.api.MoveEvent;
import incboard.api.IncBoard;


public class HexboardService implements IHexboardService, DataModelInterface {

	
	List<ThemeLandscapeHexboardDataItem> items = new ArrayList<ThemeLandscapeHexboardDataItem>();
	private int dimensions = 0;
	
	protected final Log logger = LogFactory.getLog(getClass()); 
	
    public HexboardService() {}
    
	@Override
	public List<ThemeLandscapeHexboardDataItem> provideCoordinates(List<Artwork> artworks) throws NotConvergedException, Exception{
		
		run(artworks);
		return items;
	}

	@Override
	public void moveReceived(MoveEvent event) {
    }
	
	private void run(List<Artwork> artworks) {
		items.clear();
    	IncBoard engine = new IncBoard(this, true);
        ThemeLandscapeHexboardDataItem dCell;
        for (Artwork aw : artworks) {
            dCell = new ThemeLandscapeHexboardDataItem(aw, dimensions);
            engine.add(dCell);
	        items.add(dCell);
		}
    }

	@Override
	public void setDimenions(int size) {
		dimensions = size;
		
	}
    
			
}
